package com.itlong.cloud.operate.service.impl;

import com.itlong.cloud.POJO.DTO.operate.OperateBankCardGetPageDTO;
import com.itlong.cloud.POJO.VO.operate.OperateBankCardVO;
import com.itlong.cloud.operate.dao.IOperateBankCardManageDao;
import com.itlong.cloud.operate.service.IOperateBankCardManageService;
import com.itlong.cloud.utils.data.handler.SqlUtil;
import com.itlong.cloud.utils.page.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <desc>
 *      运营银联卡管理业务处理接口实现类
 * </desc>
 *
 * @createDate 2018/09/25
 */
@Service
public class OperateBankCardManageServiceImpl implements IOperateBankCardManageService{
    @Autowired
    IOperateBankCardManageDao iOperateBankCardManageDao;

    /**
     * <desc>
     *      审核获取详情
     * </desc>
     *
     * @param bankCardId
     * @return
     * @author Jiaqi.X
     * @createDate 2018/09/25
     */
    @Override
    public OperateBankCardVO getCardInfo(String bankCardId) {
        return iOperateBankCardManageDao.getCardInfo(bankCardId);
    }

    /**
     * <desc>
     *      提交审核
     * </desc>
     *
     * @param bankCardId
     * @param checkStatus
     * @param remark
     * @param approver
     * @return
     * @author Jiaqi.X
     * @createDate 2018/09/25
     */
    @Override
    public Integer checkSubmit(String bankCardId, Integer checkStatus, String remark,String approver) {
        return iOperateBankCardManageDao.checkSubmit(bankCardId,checkStatus,remark,approver);
    }

    /**
     * <desc>
     *     获取抄银行卡账户列表
     * </desc>
     *
     * @param pageDTO   参数DTO
     * @return
     * @author Jiaqi.X
     * @createDate 2018/08/15
     */
    @Override
    public Page<OperateBankCardVO> getPage(OperateBankCardGetPageDTO pageDTO) throws Exception {
        //将DTO转换为Map params
        Map<String, Object> params = SqlUtil.convertBeanToMapParams(pageDTO);
        //分页类默认pageSize为20
        Page<OperateBankCardVO> page = new Page<>();
        page.getPage().setPageSize(pageDTO.getPageSize());
        page.getPage().setCurrentPage(pageDTO.getCurrentPage());
        params.put("currentPage",page.getPage().getStartSlip());
        params.put("pageSize",page.getPage().getPageSize());
        List<OperateBankCardVO> list = iOperateBankCardManageDao.getPage(params);
        for(OperateBankCardVO vo : list){
            int index = vo.getBankCardNo().length()/4;
            for(int i = 1;i<=index;i++){
                if((i!=index && vo.getBankCardNo().length()%4!=0)||i<index) {
                    vo.setBankCardNo(vo.getBankCardNo().substring(0, i * 4 + (i == 1 ? 0 : i - 1)) + "-" + vo.getBankCardNo().substring(i * 4 + (i == 1 ? 0 : i - 1), vo.getBankCardNo().length()));
                }
            }
        }
        //填充返回数据集
        page.setRows(list, iOperateBankCardManageDao.getPageCount(params));
        return page;
    }


    public static void main(String[] args) {
        String a = "6214837875899506";
        int index = a.length()/4;
        for(int i = 1;i<=index;i++){
            if((i!=index && a.length()%4!=0)||i<index)
            a=a.substring(0, i * 4 + (i==1 ? 0 : i-1))+"-"+a.substring(i * 4 + (i==1 ? 0 : i-1), a.length());
        }
        System.out.println(a);
    }
}
